# -*- coding:utf-8 -*-
import os


def disk_usage(path: str) -> int:
    """递归方式计算当前路径的磁盘使用情况

    :param path: 路径
    :return: 返回当前路径磁盘使用情况
    """
    total = os.path.getsize(path)
    if os.path.isdir(path):
        for file_name in os.listdir(path):
            child_path = os.path.join(path, file_name)
            total += disk_usage(child_path)

    # print(f"{total:<9} {path}")
    return total


def ls(path: str):
    if os.path.isdir(path):
        for file_name in os.listdir(path):
            child_path = os.path.join(path, file_name)
            if os.path.isdir(child_path):
                print(f"{disk_usage(child_path) / 1024:<12.3f} -D- {child_path}")
            else:
                print(f"{disk_usage(child_path) / 1024:<12.3f} -F- {child_path}")
    else:
        print(f"{disk_usage(path) / 1024:<9.2} -F- {path}")


if __name__ == "__main__":
    # disk_usage("/Users/eclipse/Desktop")
    ls("/Users/eclipse/Desktop")
